package org.opens.controller;

import org.opens.constants.GlobalConstants;
import org.opens.websocket.RedisSocketClient;
import org.opens.websocket.SimpleWebsocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: zhangyuming
 * @date: 2023/7/10 15:46
 */
@RestController
@RequestMapping(value = "/redis")
public class SimpleRedisController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private RedisSocketClient redisSocketClient;

    @RequestMapping(value = "/setValue")
    public void setValue(@RequestParam(value = "value") String value) {
        redisTemplate.opsForValue().set("setValue", value);
    }

    @RequestMapping(value = "/sendMessage")
    public void sendMessage(@RequestParam(value = "message") String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("message", message);
        redisSocketClient.sendMessage(SimpleWebsocket.REDIS_TOPIC_HANDLE_NAME, map);
    }

}
